﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace YXShop.Web.membercenter.shop.shop_info
{
    public partial class comment_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
            {
                string types = Request["Option"].Trim();
                string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                YXShop.BLL.Accessories.CommentInfo commentBll = new YXShop.BLL.Accessories.CommentInfo();
                YXShop.BLL.Accessories.CommentReply commentRBll = new YXShop.BLL.Accessories.CommentReply();
                if (types == "del")
                {
                    commentBll.Delete(Convert.ToInt32(id));
                    commentRBll.AllDelete(id);
                }
                if (types == "delAll")
                {
                    commentBll.DeleteAll(id);
                    commentRBll.AllDelete(id);
                }
                Response.End();
                return;
            }
            if (!IsPostBack)
            {
                this.lblList.Text = GetList();
            }
        }
        protected string GetList()
        {
            YXShop.BLL.Shop.Shop shopbll = new YXShop.BLL.Shop.Shop();
            List<YXShop.Model.Shop.Shop> shoplist = shopbll.GetListShopByWhere("uid=" + Session["MemberID"] + "");

            YXShop.BLL.Accessories.CommentInfo commentbll = new YXShop.BLL.Accessories.CommentInfo();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            string orderfield="[order by] commenttime desc";
            int pagesize=10;
            string conditions = " and type=2";
            if (shoplist.Count > 0)
            {
                conditions += " and commentid=" + shoplist[0].Sid;
            }
            else
            {
                return string.Empty;
            }

            ChangeHope.DataBase.DataByPage dataPage = commentbll.GetList(orderfield,pagesize, conditions);
            table.AddHeadCol("", "<input id=\"chall\" type=\"checkbox\" onclick=\"SelectAll(chall)\" />全选");
            table.AddHeadCol("", "相关商品");
            table.AddHeadCol("", "评论标题");
            table.AddHeadCol("", "评论时间");
            table.AddHeadCol("", "操作");
            table.AddRow();

            if (dataPage.DataReader != null)
            {
                while (dataPage.DataReader.Read())
                {
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=" + dataPage.DataReader["id"] + " />");
                    table.AddCol(GetProductNameById(Convert.ToInt32(dataPage.DataReader["commentid"])));
                    table.AddCol(dataPage.DataReader["title"].ToString());
                    table.AddCol(dataPage.DataReader["commenttime"].ToString());
                    table.AddCol("<a href=\"comment_revert.aspx?w_d_commentid=" + dataPage.DataReader["id"].ToString() + "\">回复</a>&nbsp;<a href=\"#\" onclick='Del(" + dataPage.DataReader["id"] + ")'>删除</a>&nbsp;<a href=\"comment_view.aspx?commentId=" + dataPage.DataReader["id"].ToString() + "\">查看</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
        private string GetProductNameById(int id)
        {
            string reStr = string.Empty;

            YXShop.BLL.Shop.Shop shopbll = new YXShop.BLL.Shop.Shop();
            YXShop.Model.Shop.Shop shopmode = shopbll.GetModelById(id);
            if (shopmode != null)
            {
                reStr = shopmode.Shopname;
            }

            return reStr;
        }
        
    }
}
